<?php
class friendmanagepage extends page {
	public $title;
	public $friends;
	public $friendClass;
	public $displayMes = "";
	public $targetFried;
	public $updateId;
	
	public function __construct(){
		$this->title = "信息管理";
		$userid = $_SESSION["userId"];
//		$this->friends = $this->getFriendList($userid);
		$this->friendClass =$this->getFriendClass($userid);
		$updateId= $_GET["id"];
		$this->updateId = $updateId;
		$post = $_POST;
		if ($post["friendName"]!=""&&$post["updateId"]==""){
			$this->addNewTongXunFriend($post);
		}else if($post["updateId"]!=""){
			$this->updateFriend($post["updateId"],$post);
		}
		if($updateId!=""){
			$this->targetFried = $this->getTargetFriend($updateId);
		}
	}
//	public function getFriendList(){
//		$dao = new friendmanagedao();
//		 
//	}
	//获取用户的通讯录分类
	public function getFriendClass($userid){
		$dao = new friendmanagedao();
		$class = $dao->getFriendClass($userid);
		$friendClass = "<option value='0' selected>默认</option>";
		if ($class[0][0]!=""){
			foreach ($class as $values){
				$id = $values[0];
				$name = $values[1];
				$friendClass .= "<option value=$id>$name</option>" ;
			}
		}
		return $friendClass;
	}
	public function addNewTongXunFriend($post){
		$post = $this->arrayDataFilter($post);
		$dao = new friendmanagedao();
		$insertTongXunData = $dao->addNewTongXunFriend($post);
		if($insertTongXunData){
			$this->displayMes = "addsuccess";
		}
		else {
			$this->displayMes = "addfailed";
		}
		
	}
	public function getTargetFriend($id){
		$dao = new friendmanagedao();
		$friend = $dao->getFriendById($id);
		return $friend;
	}
	public function updateFriend($updateId,$post){
		$dao = new friendmanagedao();
		$updateit = $dao->updateFriend($updateId,$post);
		if($updateit){
			 $this->displayMes="updatesuccess";
		}
	}
	
}

?>